package com.spider.spiderflowable.config;

import com.spider.spiderflowable.common.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @author xiong.bo
 * @version 1.0
 * @date 2020/10/31 19:02
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private JwtInterceptor jwtInterceptor;

    /**
     * 添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截路径可自行配置多个 可用 ，分隔开
        registry.addInterceptor(jwtInterceptor);
    }

    /**
     * 跨越支持
     *
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") // 允许所有路径
                .allowedOriginPatterns("*")
//                .allowedOrigins("http://192.168.2.221:8010")
                .allowedHeaders("*")// 允许哪些头部，或者使用通配符
                .allowCredentials(false)// 是否允许发送cookie
                .allowedMethods("*") // 允许哪些方法   //"GET", "POST", "DELETE", "PUT", "PATCH", "OPTIONS"
                .maxAge(3600 * 24);// 预检请求的有效期，单位为秒
    }
}

/**
 * root/xb1061787907.
 */